package com.tiemei.featurehotsale.components;

import com.alibaba.citrus.service.template.TemplateContext;
import com.alibaba.citrus.service.template.TemplateService;
import com.alibaba.citrus.service.template.support.MappedTemplateContext;
import com.taobao.search.framework.AbstractDataComponent;
import com.taobao.search.framework.DataComponentContext;
import com.tiemei.featurehotsale.datamodel.PureDataModel;

/**
 * 调用webx的template service渲染输出
 *
 * @author tiemei.jdk
 * @date   2012-10-30
 */
public class TemplateServiceComponent extends AbstractDataComponent<PureDataModel>{
	
	private TemplateService templateService;
	
	public void setTemplateService(TemplateService templateService) {
        this.templateService = templateService;
    }

	public boolean run(String name, DataComponentContext<? extends PureDataModel> context, PureDataModel dataModel) throws Exception {
		System.out.println("TemplateServiceComponent...");
		String template = "hello.vm";
        TemplateContext templateContext = new MappedTemplateContext();

        templateContext.put("pageModel", dataModel.getPageModel());
        templateService.writeTo(template, templateContext, dataModel.getResponse().getWriter());
	    return true;
    }

}
